package com.kaiyidiannao.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.kaiyidiannao.main.R;
import com.kaiyidiannao.model.bean.Auction;
import com.kaiyidiannao.model.bean.FavoritesBean;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by mark on 2014/4/16.
 */
public class MyFavoritesAdapter extends BaseAdapter {
    private ImageLoader imageLoader;
    private LayoutInflater layoutInflater;
    private List<FavoritesBean> list = new ArrayList<FavoritesBean>();

    public MyFavoritesAdapter(Context context, List<FavoritesBean> list) {
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(context));
        this.list = list;
        this.layoutInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null;
        TextView title = null;
        TextView prices = null;
        FavoritesBean favoritesBean = list.get(position);
        if (convertView==null)
        {
            convertView=layoutInflater.inflate(R.layout.favorites_item,null);
        }
        imageView = (ImageView) convertView.findViewById(R.id.favorites_image);
        title = (TextView) convertView.findViewById(R.id.title);
        prices = (TextView) convertView.findViewById(R.id.prices);
        title.setText(favoritesBean.getTitle());
        prices.setText(favoritesBean.getPrices());
        imageLoader.displayImage(favoritesBean.getThumb(),imageView);
        return convertView;
    }
}
